/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GoLib-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_01_01			*/
/*	File:		GoTime.go			*/
/********************************************************/

package GoCls

import (
	T "time"
	. "GoGlb"
)

func GoTimeUnix() int64 {
	return T.Now().Unix()
}

func GoTimeSleep(s int, m int) {
	T.Sleep(T.Duration(1e9 * s + m))
}

// Date
type GoDate struct {
	year	int
	mon	T.Month
	day	int
}

func (d *GoDate) GoDateNow() {
	d.year, d.mon, d.day = T.Now().UTC().Date()
}

func (d *GoDate) GoDateValue() string {
	return GoValue("%d-%d-%d", d.year, d.mon, d.day)
}

func (d *GoDate) GoDateString() string {
	d.GoDateNow()
	return d.GoDateValue()
}

// Clock
type GoClock struct {
	hour	int
	min	int
	sec	int
}

func (c *GoClock) GoClockNow() {
	c.hour, c.min, c.sec = T.Now().UTC().Clock()
}

func (c *GoClock) GoClockValue() string {
	return GoValue("%02d:%02d:%02d", c.hour, c.min, c.sec)
}

func (c *GoClock) GoClockString() string {
	c.GoClockNow()
	return c.GoClockValue()
}

// Stamp
type GoStamp struct {
	date	GoDate
	clock	GoClock
}

func (s *GoStamp) GoStampNow() {
	s.date.GoDateNow()
	s.clock.GoClockNow()
}

func (s *GoStamp) GoStampValue() string {
	return s.date.GoDateValue() + " " + s.clock.GoClockString()
}

func (s *GoStamp) GoStampString() string {
	s.GoStampNow()
	return s.GoStampValue()
}

// Timer
type GoTimer struct {
	on	T.Time
	off	T.Time
}

func (t *GoTimer) GoTimerOn() {
	t.on = T.Now()
}

func (t *GoTimer) GoTimerOff() {
	t.off = T.Now()
}

func (t *GoTimer) GoTimerCost() {
	GoPrtln("Use time:", t.off.Sub(t.on))
}

func (t *GoTimer) GoTimerSince() {
	GoPrtln("Use time:", T.Since(t.on))
}
